#include "../include/cc_lstack.h"

static cc_bool_t cc_lstack_push(cc_lstack_t lstack, void* data) {
	lstack->size++;
	return lstack->parent->insert_head(lstack->parent, data);
}

static void* cc_lstack_pop(cc_lstack_t lstack) {
	lstack->size--;
	return lstack->parent->delete_head(lstack->parent);
}

static void cc_lstack_toString(cc_lstack_t lstack, void (*callback)(void* data)) {
	lstack->parent->toString(lstack->parent, callback);
}
static cc_bool_t cc_lstack_isEmpty(cc_lstack_t lstack) {
	return lstack->size == 0 ? 1 : 0;
}

static cc_bool_t cc_lstack_length(cc_lstack_t lstack) {
	return lstack->parent->size;
}

static void cc_lstack_clear(cc_lstack_t lstack) {
	lstack->parent->clear(lstack->parent);
	lstack->size = lstack->parent->size;
}

static void cc_lstack_free(cc_lstack_t lstack) {
	lstack->parent->free(lstack->parent);
	free(lstack);
	lstack = NULL;
}

cc_lstack_t CC_New_LStack(cc_uint8_t* name) {
	cc_lstack_t lstack = new(cc_lstack);
	assert(lstack != NULL);
	lstack->parent = CC_New_List(name);
	lstack->parent->parent->type = CC_Class_LStack;
	lstack->size = 0;
	lstack->push = cc_lstack_push;
	lstack->pop = cc_lstack_pop;
	lstack->toString = cc_lstack_toString;
	lstack->isEmpty = cc_lstack_isEmpty;
	lstack->length = cc_lstack_length;
	lstack->clear = cc_lstack_clear;
	lstack->free = cc_lstack_free;
	return lstack;
}